#!/bin/sh

set -e

ret=0
i=0
tmpdir=$(mktemp -d --tmpdir glib-run-installed-tests.XXXXXX)
LOG_DIR="./test_result.log"


echo > $LOG_DIR

for testcase in /usr/libexec/installed-tests/glib/*;
do
    if [ "$(file -b $testcase | awk -F',' '{print $1}')" != "ELF 64-bit LSB pie executable" ]; then
        continue
    fi

    i=$(($i + 1))
    echo "=============== $i = $testcase ===============" >> $LOG_DIR
    set +e
    timeout 300s $testcase 2>&1 >> $LOG_DIR
    case "$?" in
        (0)
            echo "SUCCESS $i - $testcase" >> $LOG_DIR
            ;;
        (77)
            echo "SUCCESS $i # SKIP $testcase" >> $LOG_DIR
            ;;
        (*)
            echo "FAILED $i - $testcase" >> $LOG_DIR
            ret=1
            ;;
    esac
done

rm -rf $tmpdir
echo "TOTAL NUMBER OF TESTCASE: $i" >> $LOG_DIR
exit $ret
